<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <!-- 
        2. 已知数组arr，利用编程以最少的步骤实现以下功能
            a. 获取数组中最大值、最小值
            b. 计算平均值
            c. 求和
            d. 降序排序
            e. 去重
        const arr = [5,3,2,8,3,11,18,2,6,5,10,12,14,7]
     -->
</head>
<body>
    <script>
        const arr = [5,3,2,8,3,11,18,2,6,5,10,12,14,7]

        // a. 获取数组中最大值、最小值
        // d. 降序排序
        const sortArr = arr.sort(function(a,b){
            return b-a
        })
        const min = sortArr[arr.length-1]  
        const max = sortArr[0]  
        console.log(sortArr,max,min)  
        // [18, 14, 12, 11, 10, 8, 7, 6, 5, 5, 3, 3, 2, 2]  18  2

        // b. 计算平均值
        // c. 求和
        const sum = arr.reduce(function(prev,item){
            return prev+item
        },0)
        const aveNum = sum/arr.length
        console.log(sum,aveNum) //106 7.571428571428571

        // e. 去重
        const set = new Set(arr)
        const newArr = Array.from(set)
        console.log(newArr) //[18, 14, 12, 11, 10, 8, 7, 6, 5, 3, 2]
    </script>
</body>
</html>